package com.codejam.winter.util.mybatis;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

/**
 * @author Admin
 */
public class MyBatisUtils
{
    static SqlSessionFactory factory;

    public static SqlSession getSession()
    {
        if(factory==null)
        {
            String resource="mybatis/SqlMapConfig.xml";
            InputStream is = MyBatisUtils.class.getClassLoader().getResourceAsStream(resource);
            factory = new SqlSessionFactoryBuilder().build(is);
        }
        return factory.openSession();
    }
}
